/*******************************************************************************
 * Copyright (c) 2008 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.classdiagram.tabbedproperties.section;

import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.TypedElement;

import com.cea.papyrus.core.filters.TypeFilter;
import com.cea.papyrus.core.tabbedproperties.AbstractSelectionElementSection;

/**
 * This class is used to display section about the type of a TypedElement
 */
public class TypeSection extends AbstractSelectionElementSection {

	/**
	 * Creates a new TypeSection.
	 */
	public TypeSection() {
		super("Type: ", new TypeFilter());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public NamedElement getReferencedElementToDisplay() {
		if(getElement() instanceof TypedElement) {
			Type type = ((TypedElement)getElement()).getType();
			if(type!=null) {
				return type;
			}
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void removeReferencedElement() {
		if(getElement() instanceof TypedElement) {
			((TypedElement)getElement()).setType(null);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setReferencedElement(NamedElement element) {
		if (element instanceof Type){
			Type type = (Type)element;
			if(getElement() instanceof TypedElement) {
				((TypedElement)getElement()).setType(type);
			}
		}
	}
}